home *** CD-ROM | disk | FTP | other *** search
/ CICA 1993 April / CICA MS Windows - April 1993.iso / unzipped / programr / multipad / mpinit.c < prev    next >
Text File  |  1992-07-17  |  5KB  |  158 lines

  1. /***************************************************************************
  2.  *                                       *
  3.  *  MODULE    : MpInit.c                           *
  4.  *                                       *
  5.  *  PURPOSE    : Contains initialization code for MultiPad.           *
  6.  *                                       *
  7.  *  FUNCTIONS    : InitializeApplication() - Sets up Class data structure   *
  8.  *                        and registers window class.    *
  9.  *                                       *
  10.  *          InitializeInstance ()   - Does a per-instance initial-   *
  11.  *                        ization of MultiPad. Creates   *
  12.  *                        the "frame" and MDI client.    *
  13.  *                                       *
  14.  ***************************************************************************/
  15. // COPYRIGHT:
  16. //
  17. //   (C) Copyright Microsoft Corp. 1992.  All rights reserved.
  18. //
  19. //   You have a royalty-free right to use, modify, reproduce and
  20. //   distribute the Sample Files (and/or any modified version) in
  21. //   any way you find useful, provided that you agree that
  22. //   Microsoft has no warranty obligations or liability for any
  23. //   Sample Application Files which are modified.
  24.  
  25.  
  26. #include "multipad.h"
  27. #include "commdlg.h"
  28.  
  29. PRINTDLG pd;                  /* Common print dialog structure */
  30.  
  31. char szFrame[] = "mpframe";   /* Class name for "frame" window */
  32. char szChild[] = "mpchild";   /* Class name for MDI window     */
  33.  
  34. /****************************************************************************
  35.  *                                        *
  36.  *  FUNCTION   : InitializeApplication ()                    *
  37.  *                                        *
  38.  *  PURPOSE    : Sets up the class data structures and does a one-time        *
  39.  *         initialization of the app by registering the window classes*
  40.  *                                        *
  41.  *  RETURNS    : TRUE  - If RegisterClass() was successful for both classes.*
  42.  *         FALSE - otherwise.                        *
  43.  *                                        *
  44.  ****************************************************************************/
  45.  
  46. BOOL FAR PASCAL InitializeApplication()
  47. {
  48.     WNDCLASS    wc;
  49.  
  50.     /* Register the frame class */
  51.     wc.style         = 0;
  52.     wc.lpfnWndProc   = MPFrameWndProc;
  53.     wc.cbClsExtra    = 0;
  54.     wc.cbWndExtra    = 0;
  55.     wc.hInstance     = hInst;
  56.     wc.hIcon         = LoadIcon(hInst,IDMULTIPAD);
  57.     wc.hCursor         = LoadCursor(NULL,IDC_ARROW);
  58.     wc.hbrBackground = COLOR_APPWORKSPACE+1;
  59.     wc.lpszMenuName  = IDMULTIPAD;
  60.     wc.lpszClassName = szFrame;
  61.  
  62.     if (!RegisterClass (&wc) )
  63.     return FALSE;
  64.  
  65.     /* Register the MDI child class */
  66.     wc.lpfnWndProc   = MPMDIChildWndProc;
  67.     wc.hIcon         = LoadIcon(hInst,IDNOTE);
  68.     wc.lpszMenuName  = NULL;
  69.     wc.cbWndExtra    = CBWNDEXTRA;
  70.     wc.lpszClassName = szChild;
  71.  
  72.     /* fill in non-variant fields of PRINTDLG struct. */
  73.  
  74.     pd.lStructSize    = sizeof(PRINTDLG);
  75.     pd.hDevMode       = NULL;
  76.     pd.hDevNames      = NULL;
  77.     pd.Flags          = PD_RETURNDC | PD_NOSELECTION | PD_NOPAGENUMS;
  78.     pd.nCopies        = 1;
  79.  
  80.    
  81.    if (!RegisterClass(&wc))
  82.     return FALSE;
  83.  
  84.     return TRUE;
  85.  
  86. }
  87.  
  88. /****************************************************************************
  89.  *                                        *
  90.  *  FUNCTION   : InitializeInstance ()                        *
  91.  *                                        *
  92.  *  PURPOSE    : Performs a per-instance initialization of MultiPad. It     *
  93.  *         also creates the frame and an MDI window.            *
  94.  *                                        *
  95.  *  RETURNS    : TRUE  - If initialization was successful.            *
  96.  *         FALSE - otherwise.                        *
  97.  *                                        *
  98.  ****************************************************************************/
  99. BOOL FAR PASCAL InitializeInstance(LPSTR lpCmdLine, WORD nCmdShow)
  100. {
  101.     extern HWND  hwndMDIClient;
  102.     char     sz[80], *pCmdLine;
  103.  
  104.     /* Get the base window title */
  105.     LoadString (hInst, IDS_APPNAME, sz, sizeof(sz));
  106.  
  107.     /* Create the frame */
  108.     hwndFrame = CreateWindow (szFrame,
  109.                   sz,
  110.                   WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
  111.                   CW_USEDEFAULT,
  112.                   0,
  113.                   CW_USEDEFAULT,
  114.                   0,
  115.                   NULL,
  116.                   NULL,
  117.                   hInst,
  118.                   NULL);
  119.  
  120.     if ((!hwndFrame) || (!hwndMDIClient))
  121.     return FALSE;
  122.  
  123.     pd.hwndOwner = hwndFrame;
  124.  
  125.    /* Load main menu accelerators */
  126.     if (!(hAccel = LoadAccelerators (hInst, IDMULTIPAD)))
  127.     return FALSE;
  128.  
  129.     /* Display the frame window */
  130.     ShowWindow (hwndFrame, nCmdShow);
  131.     UpdateWindow (hwndFrame);
  132.  
  133.     /* If the command line string is empty, nullify the pointer to it 
  134.     ** else copy command line into our data segment 
  135.     */
  136.     if ( lpCmdLine && !(*lpCmdLine))
  137.          pCmdLine = NULL;
  138.     else {
  139.         pCmdLine = (char *) LocalAlloc(LPTR, lstrlen(lpCmdLine) + 1);
  140.         if (pCmdLine)
  141.            lstrcpy(pCmdLine, lpCmdLine);
  142.     }
  143.  
  144.     /* Add the first MDI window */
  145.     AddFile (pCmdLine);
  146.  
  147.     /* if we allocated a buffer then free it */
  148.     if (pCmdLine)
  149.         LocalFree((LOCALHANDLE) pCmdLine);
  150.  
  151.     /* Default to minimized windows after the first. */
  152.     styleDefault = 0L;
  153.  
  154.     return TRUE;
  155.  
  156. }
  157. 
  158.